# -*- coding: utf-8 -*-

from core.viewset import CustomModelViewSet
from core.response import JsonResponse
from apps.rms.models import PacketType
from rest_framework.decorators import action
from apps.rms.packet.serializers import *
from apps.rms.packet.resources import *
from apps.rms.packet.filters import *


class PacketTypeViewSet(CustomModelViewSet):
    """
    报文类型管理接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """

    queryset = PacketType.objects.all()
    serializer_class = PacketTypeSerializer
    filterset_class = PacketTypeFilterSet
    import_resources = PacketTypeResouces
    export_resources = PacketTypeResouces

    @action(detail=False, methods=["GET"])
    def treeselect(self, request, *args, **kwargs):
        queryset = PacketType.objects.all()
        serializer = PacketTreeSelectSerializer(queryset, many=True, request=request)
        return JsonResponse(data=serializer.data, msg="获取成功")


class PacketFieldViewSet(CustomModelViewSet):
    """
    报文字段接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """

    queryset = PacketField.objects.all()
    serializer_class = PacketFieldSerializer
    filterset_class = PacketFieldFilterSet
    import_resources = PacketFieldResouces
    export_resources = PacketFieldResouces
